//
//  LoginViewController.m
//  UI14_豆瓣电影更新版
//
//  Created by dllo on 16/1/3.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "LoginViewController.h"
#import "MyViewController.h"
#import "RegisterViewController.h"
@interface LoginViewController ()<UITextFieldDelegate>

@end

@implementation LoginViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)dealloc {
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"用户登录";
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    self.navigationItem.leftBarButtonItem = item;
    [item release];
    [self handel];
    
    
    
    
}
// 左item方法
- (void)itemAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)handel {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 50, 60, 40)];
    [self.view addSubview:label];
    label.text = @"用户名:";
    [label release];
    
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(30, 120, 60, 40)];
    [self.view addSubview:label2];
    label2.text = @"密码:";
    [label2 release];
    
    UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(120, 50, 200, 40)];
    [self.view addSubview:tf];
    tf.borderStyle = UITextBorderStyleBezel;
    tf.layer.borderWidth = 2;
    tf.layer.cornerRadius = 10;
    tf.clearButtonMode = YES;
    tf.tag = 1000;
    tf.delegate = self;
//    tf.backgroundColor = [UIColor whiteColor];
    tf.placeholder = @"请输入用户名";
    [tf release];
    
    UITextField *tff = [[UITextField alloc] initWithFrame:CGRectMake(120, 120, 200, 40)];
    [self.view addSubview:tff];
    tff.placeholder = @"请输入密码";
    tff.layer.borderWidth = 2;
    tff.borderStyle = UITextBorderStyleBezel;
    tff.layer.cornerRadius = 10;
    tff.secureTextEntry = YES;
    tff.clearButtonMode = YES;
    tff.delegate  =self;
    tff.tag = 1001;
    tff.layer.masksToBounds = YES;
    [tff release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"登录" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor greenColor];
    button.frame = CGRectMake(50, 200, 100, 40);
    [self.view addSubview:button];
    button.layer.cornerRadius = 10;
    button.layer.masksToBounds = YES;
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button2 setTitle:@"注册" forState:UIControlStateNormal];
    [self.view addSubview:button2];
    button2.layer.cornerRadius = 10;
    button2.backgroundColor = [UIColor orangeColor];
    button2.layer.masksToBounds = YES;
    button2.frame = CGRectMake(210, 200, 100, 40);
    [button2 addTarget:self action:@selector(buttonAction2:) forControlEvents:UIControlEventTouchUpInside];
    
    
}
// 登录方法
- (void)buttonAction:(UIButton *)button {
    MyViewController *my = [[MyViewController alloc] init];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"注销" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction2:)];
    my.navigationItem.rightBarButtonItem = item;
    [item release];
    _block(@"注销");
    UITextField *tf = [self.view viewWithTag:1000];
    NSLog(@"%@", tf);
    // 判断输入框是否为空
    if (!tf.text.length) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名不能为空" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:^{
            
        }];
        
        
        
    }
    [self.navigationController popViewControllerAnimated:NO];
    
//    _block2(tf.text);
}
//
- (void)itemAction2:(UIBarButtonItem *)item {
    
}
// 注册方法
- (void)buttonAction2:(UIButton *)button {
    RegisterViewController *reg = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:reg animated:NO];
    [reg release];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [textField resignFirstResponder];
    UITextField *tf = [self.view viewWithTag:textField.tag + 1];
    [tf becomeFirstResponder];
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
